package utils;

import java.sql.*;

/**
 * 数据库连接帮助类
 */
public class DBUtils {
    /**
     * 获取连接资源
     * @return
     */
    public static Connection getConnection() {
        Connection conn = null;
        try {
            Class.forName("oracle.jdbc.OracleDriver");
            conn = DriverManager.getConnection("jdbc:oracle:thin:@//localhost:1521/ORCL","scott","tiger");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return conn;
    }

    /**
     * 关闭连接资源
     * @param conn
     * @param st
     */
    public static void close( Connection conn , Statement st ) {
        try {
            if ( st != null ) st.close();
            if ( conn != null ) conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
